package com.ruoyi.project.system.function.domain;

import com.ruoyi.project.system.dict.utils.DictUtils;
import com.ruoyi.project.system.function.bean.CategoryMap;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @program: NH
 * @description: 字典映射后实体
 * @author: 郑吉志
 * @create: 2023-02-20 17:24
 **/
@Data
@EqualsAndHashCode
public class Detail {
    int id;
    int incomeDataId;
    String firstCategory;
    String secondaryCategory;
    String tertiaryCategory;
    String quantity;
    String amount;

    public Detail() {
    }

    public Detail(int id, int incomeDataId, String firstCategory, String secondaryCategory, String tertiaryCategory, String quantity, String amount) {
        this.id = id;
        this.incomeDataId = incomeDataId;
        this.firstCategory = firstCategory;
        this.secondaryCategory = secondaryCategory;
        this.tertiaryCategory = tertiaryCategory;
        this.quantity = quantity;
        this.amount = amount;
    }
    //数据库对象映射为展示对象-字典映射-Integer>>String
    public Detail(DetailDB db){
        this.id=db.getId();
        String firstCategory=DictUtils.getDictLabel("first_category_type",db.getFirstCategory().toString());
        String firstType=CategoryMap.map.get(firstCategory);
        String secondaryCategory=DictUtils.getDictLabel(firstType,db.getSecondaryCategory().toString());
        String secondType=CategoryMap.map.get(secondaryCategory);


        String tertiaryCategory;
        if (CategoryMap.map.containsKey(secondaryCategory)&&db.getTertiaryCategory()==0)
            tertiaryCategory=secondaryCategory;
        else
            tertiaryCategory=DictUtils.getDictLabel(secondType,db.getTertiaryCategory().toString());

        this.firstCategory=firstCategory;
        this.secondaryCategory=secondaryCategory;

        this.tertiaryCategory=tertiaryCategory;

        this.quantity=db.getQuantity()==null?"":String.format("%.2f",db.getQuantity());
        this.amount=db.getAmount()==null?"":String.format("%.2f",db.getAmount());
    }
}
